import 'package:get/get.dart';
import 'package:mmkv/mmkv.dart';
import 'package:myapp/app/data/entities/key_value_model.dart';
import 'package:myapp/app/data/repository/comm_repository.dart';
import 'package:myapp/generated/locales.g.dart';

class BrokerinfoController extends GetxController {
  final RxList<String> labels = <String>[].obs;

  final RxList<List<KeyValue>> data = <List<KeyValue>>[].obs;

  final ICommRepository _commRepository = Get.find();

  final String YES = LocaleKeys.yes.tr;
  final String NO = LocaleKeys.no.tr;

  @override
  void onInit() {
    super.onInit();
  }

  _initLabels() {
    var data = <String>[];
    data.add("经纪属性");
    data.add("Information");
    data.add("CREDIT CARD AUTHORIZATION FORM");
    labels.value = data;
  }

  _getYesOrNo(int? data) {
    return data == null ? "-" : (data == 0 ? NO : YES);
  }

  _getType(int? data) {
    return data == null? "-" : (data == 0 ? "个体经纪": "团队经纪");
  }

  _getGender(int? data) {
    return data == null ? null : (data == 0? "male" : "fmale");
  }

  _getCard(int? data) {
    return data == null ? null : (data == 0? "Visa":"MasterCard");
  }

  _initData() async {
    try {
      var bw = await _commRepository.getBwRealtor();

      List<List<KeyValue>> parentList = <List<KeyValue>>[];
      List<KeyValue> list1 = <KeyValue>[];
      list1.add(KeyValue(key: LocaleKeys.docusign_item_is_just_license.tr, value: _getYesOrNo(bw.isnew)));
      list1.add(KeyValue(key: LocaleKeys.docusign_item_is_other_into.tr, value: _getYesOrNo(bw.otherprovince)));
      list1.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_prec.tr, value: _getYesOrNo(bw.prec)));
      list1.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_lease_license.tr, value: _getYesOrNo(bw.rental)));
      list1.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_broker_type.tr, value: _getType(bw.type)));
      list1.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_cost.tr, value: "1000/年"));
      parentList.add(list1);

      List<KeyValue> list2 = <KeyValue>[];
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_first_name.tr, value: bw.firstname));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_last_name.tr, value: bw.lastname));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_name_of_applicant.tr, value: bw.applicant));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_gender.tr, value: _getGender(bw.gender)));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_city.tr, value: bw.city));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_postal_code.tr, value: bw.zipcode));

      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_address.tr, value: bw.address));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_cellular.tr, value: bw.celluar));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_email.tr, value: bw.email));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_date_of_birth.tr, value: bw.birthday));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_social.tr, value: bw.insurance));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_gst.tr, value: bw.gst));

      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_mebmer_lice.tr, value: bw.license));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_membership_id.tr, value: bw.membership));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_name_of_prec.tr, value: bw.precname));
      list2.add(KeyValue(
          key: LocaleKeys.docusign_item_broker_info_emergencey_contact.tr, value: bw.emergencyperson));
      list2.add(
          KeyValue(key: LocaleKeys.docusign_item_broker_info_phone_number.tr, value: bw.emergencyphone));
      list2.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_relationship.tr, value: bw.relationship));
      parentList.add(list2);

      List<KeyValue> list3 = <KeyValue>[];
      list3.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_type_of_card.tr, value: _getCard(bw.cardtype)));
      list3.add(KeyValue(key: LocaleKeys.docusign_item_broker_info_card_number.tr, value: bw.cardno));
      list3.add(KeyValue(key: LocaleKeys.docusign_item_broker_expiration_date.tr, value: bw.cardexpire));
      parentList.add(list3);

      data.value = parentList;
    } catch (e) {

    }

  }

  @override
  void onReady() {
    super.onReady();
    _initLabels();
    _initData();
  }

  @override
  void onClose() {}
}
